package AsciiCipher;

import java.util.Scanner;

public class AsciiCipher {
    // 加密方法
    public static String encrypt(String text) {
        StringBuilder encryptedText = new StringBuilder();
        for (char c : text.toCharArray()) {
            char encryptedChar = (char) (c + 1);
            encryptedText.append(encryptedChar);
        }
        return encryptedText.toString();
    }

    // 解密方法
    public static String decrypt(String encryptedText) {
        StringBuilder decryptedText = new StringBuilder();
        for (char c : encryptedText.toCharArray()) {
            char decryptedChar = (char) (c - 1);
            decryptedText.append(decryptedChar);
        }
        return decryptedText.toString();
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入明文:");
        String plainText = scanner.nextLine();

        // 加密
        String encryptedText = encrypt(plainText);
        System.out.println("使用的加密方法: ASCII码加1");
        System.out.println("加密后的文本: " + encryptedText);

        // 解密
        String decryptedText = decrypt(encryptedText);
        System.out.println("解密后的文本: " + decryptedText);
    }
}
